package com.example.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


/**
 * @author ljs
 * @date 2025/7/16
 */
// 在订单服务(消费者)中声明
@Configuration
public class OrderRabbitConfig {
    // 订单业务队列+死信队列
    @Bean
    public Queue orderQueue() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-dead-letter-exchange", "order.dlx.exchange"); // 死信交换机
        return new Queue("order.queue", true, false, false, args);
    }


    @Bean
    public DirectExchange orderExchange() {
        return new DirectExchange("order.exchange");
    }

    // 绑定关系
    @Bean
    public Binding bindOrder() {
        return BindingBuilder.bind(orderQueue())
                .to(orderExchange()).with("order.routingKey");
    }
}
